package baidu.reader.common.utils 
{
	
	public class Zh2Number extends Object
	{
		public function Zh2Number()
		{
			super();
			return;
		}
		
		public static function fromString(arg1:String):Number
		{
			var loc1:*=null;
			var loc2:*=0;
			var loc3:*=0;
			var loc4:*=0;
			var loc5:*=null;
			var loc6:*=0;
			var loc7:*=0;
			if (!new RegExp("[十百千万]+").test(arg1))
			{
				loc3 = 0;
				loc1 = arg1.split("");
				loc2 = (loc1.length - 1);
				while (loc2 >= 0) 
				{
					loc4 = Math.pow(10, (loc1.length - 1) - loc2);
					loc3 = loc3 + stringMap[loc1[loc2]] * loc4;
					loc2 = (loc2 - 1);
				}
				return loc3;
			}
			tempNumbers = [];
			loc1 = arg1.split("");
			tempNumbers.push(stringMap[loc1[0]]);
			loc2 = 1;
			while (loc2 < loc1.length) 
			{
				loc5 = loc1[loc2];
				if ((loc6 = stringMap[loc5] as int) > tempNumbers[(tempNumbers.length - 1)])
				{
					loc3 = 0;
					loc7 = (tempNumbers.length - 1);
					while (loc7 >= 0) 
					{
						if (loc6 > tempNumbers[loc7])
						{
							loc3 = loc3 + tempNumbers[loc7];
							tempNumbers.splice(loc7, 1);
						}
						loc7 = (loc7 - 1);
					}
					tempNumbers.push(loc3 * loc6);
				}
				else 
				{
					if (loc6 != 0)
					{
						tempNumbers.push(loc6);
					}
				}
				++loc2;
			}
			return arraySum(tempNumbers);
		}
		
		private static function arraySum(arg1:Array):int
		{
			var loc1:*=0;
			var loc2:*=0;
			while (loc2 < arg1.length) 
			{
				loc1 = loc1 + arg1[loc2];
				++loc2;
			}
			return loc1;
		}
		
		
		{
			stringMap = [];
			stringMap["亿"] = 100000000;
			stringMap["万"] = 10000;
			stringMap["千"] = 1000;
			stringMap["百"] = 100;
			stringMap["十"] = 10;
			stringMap["零"] = 0;
			stringMap["一"] = 1;
			stringMap["二"] = 2;
			stringMap["两"] = 2;
			stringMap["三"] = 3;
			stringMap["四"] = 4;
			stringMap["五"] = 5;
			stringMap["六"] = 6;
			stringMap["七"] = 7;
			stringMap["八"] = 8;
			stringMap["九"] = 9;
		}
		
		private static var stringMap:Array;
		
		private static var tempNumbers:Array;
	}
}


